package com.soft.sitegenerator.business.hibernate;

import java.util.Collection;
import java.util.Date;

import com.soft.sitegenerator.dao.HibernateDAO;
import com.soft.sitegenerator.exceptions.ObjectNotFoundException;

public class Person {
	private Long id;

	private String name;

	private String surname;

	private Date bornDate;

	private String mail;

	private String address;

	private String city;

	private String postalCode;

	private String state;

	private String country;

	private String phoneNumber;

	private User user;

	private HibernateDAO hibernateDAOHib;

	
	public String getCompleteName() {
		return name+" "+surname;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Date getBornDate() {
		return bornDate;
	}

	public void setBornDate(Date bornDate) {
		this.bornDate = bornDate;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	// HIBERNATE DAO
	public HibernateDAO getHibernateDAOHib() {
		return hibernateDAOHib;
	}

	public void setHibernateDAOHib(HibernateDAO hibernateDAOHib) {
		this.hibernateDAOHib = hibernateDAOHib;
	}

	public void load() throws ObjectNotFoundException {
		hibernateDAOHib.load(this, this.id);
	}

	public void save() {
		hibernateDAOHib.save(this);
	}

	public void update() {
		hibernateDAOHib.update(this);
	}

	public void delete() {
		hibernateDAOHib.delete(this);
	}

	public boolean exist() {
		try {
			hibernateDAOHib.exist(this, this.id);
		} catch (ObjectNotFoundException e) {
			return false;
		}
		return true;
	}

	public Collection findAll() {
		return hibernateDAOHib.find("from Person order by surname");
	}

}
